﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class cn_fileupload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnOk_Click(object sender, EventArgs e)
    {
        string sort = Request.QueryString["s"].ToString();
        string id = Request.QueryString["id"].ToString();
        if (this.FileUpload1.HasFile)
        {
            string filename=DateTime.Now.Ticks.ToString() + this.FileUpload1.FileName.Substring(this.FileUpload1.FileName.LastIndexOf("."));
            switch (sort)
            {
                case "1": //产品分类图片
                    string img = "upload/product/" + filename;
                    this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/"+img));
                    CProduct pc = new CProduct();
                    pc.SetImage(int.Parse(id), img,Page);
                    break;   
                case "2"://上传文件
                    string file = "upload/file/" + filename;
                    this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/" + file));
                    CFile f = new CFile();
                    f.SetPath(Convert.ToInt32(id), file, Page);
                    break;
                case "3"://上传引导页图片
                    string iimg = "upload/index/" + filename;
                    this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/" + iimg));
                    CIndex index = new CIndex();
                    index.UpdatePath(Convert.ToInt32(id), iimg, Page);
                    break;
                case "4":
                    string himg = "upload/home/" + filename;
                    this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/" + himg));
                    CCommon com = new CCommon();
                    com.Update(Convert.ToInt32(id), himg);
                    break;
                default:
                    break;
            }
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "<script>alert('上传成功!');this.close();window.opener.location.reload();</script>");
        }
    }
}